﻿using System.Data;

namespace CoreHelper
{
    /// <summary>
    /// DataTable类，创建DataTable
    /// </summary>
    public static class DataTableHelper
    {
        #region 创建DataTable
        /// <summary>
        /// 创建DataTable
        /// </summary>
        /// <param name="columns">列集合</param>
        /// <example>
        ///     DataTable结构示例
        ///     <code>
        ///         string[] columns = { "column1", "column2", "column3", "column4", "column5",... };
        ///         DataTable dt = CoreHelper.DataTableHelper.CreateDataTable(columns);
        ///         foreach(var item in list)
        ///         {
        ///         dt.Rows.Add( "column1", "column2", "column3", "column4", "column5",...);
        ///         }
        ///     </code>
        /// </example>
        public static DataTable CreateDataTable(string[] columns)
        {
            DataTable dt = new DataTable();
            foreach (var item in columns)
            {
                dt.Columns.Add(item);
            }
            return dt;
        }
        #endregion
    }
}
